<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>滴滴法律</title>
	<link rel="stylesheet" type="text/css" href="css/normalize.css">
	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<!--[if lt IE 9]> 
		<script> src="js/html5shiv.min.js"></script> 
	<![endif]-->
</head>
<body>
	<div class="well well-sm">法律知识 / 添加文章</div>
	<form class="form-horizontal" method="post" action="" id="topic-form" style="margin-top:10px;">
		<div class="form-group">
			<label for="part" class="col-sm-2 control-label">分类</label>
			<div class="col-sm-2">
				<select name="typeid" id="part" class="form-control">
					<option value="1">医疗相关</option>
					<option value="2">交通相关</option>
					<option value="3">科技相关</option>
					<option value="4">社会相关</option>
					<option value="5">婚姻相关</option>
				</select>					
			</div>
		</div>
		<div class="form-group">
			<label for="title" class="col-sm-2 control-label">话题</label>
			<div class="col-sm-4">
				<input id="themename" type="text" name="themename" class="form-control" placeholder="请填写标题">
			</div>
		</div>
		<div class="form-group">
			<label for="content" class="col-sm-2 control-label">内容</label>
			<div class="col-sm-4">
				<textarea id="themecontent" name="themecontent" class="form-control" placeholder="请填写文章内容" rows="4"></textarea>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-4">
				<input type="button" id="add-btn" class="btn btn-success" value="添加">
			</div>
		</div>
	</form>
	
</body>

<script type="text/javascript">
 
 $("#add-btn").on("click",function() {
    var flag = true;
 	var themename = $("#themename").val();
 	var themecontent = $("#themecontent").val();
 	if (themename == "") {
 		alert("请填写话题！");
 		flag = false;
 	}else if (themecontent == "") {
 		alert("请填写内容！");
 		flag = false;
 	}
 	
 	if (flag) {
 		$.ajax({
 			type:"post",
 			url:"topic/add",
 			data:$("#topic-form").serialize(),
 			success:function(data) {
 				alert(data.msg);
 				if (data.code == 200) {
 					location.reload();
 				}
 			}
 		});
 	}
 
 });
</script>
</html>